--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
      name:  <unnamed>
       log:  2_SingleWomen_simCredit.log
  log type:  text
 opened on:  13 Apr 2018, 11:52:42

. ***************************************************************************;
. * GENERATE SIMULATED CREDIT ;
. ***************************************************************************;
. local beginTime "DateTime: $S_DATE $S_TIME";

. set more off ;

. set linesize 200 ;

. set mem 5g ;
set memory ignored.
    Memory no longer needs to be set in modern Statas; memory adjustments are performed on the fly automatically.

. set seed 123456789 ;

. cd "$dataDir" ;

. ***************************************************************************;
. * A LITTLE PROGRAM THAT TELLS US THE SIZE OF DATA IN MEMORY IN GIGS AND MEGS ;
. ***************************************************************************;
. program define sizer ;
  1.         qui des, short ;
  2.         di "OBSERVATIONS: " r(N) ;
  3.         di "DATA IN MEMORY (gbs): " round((r(width)+4)*r(N)/1024^3,.001) ;
  4.         di "DATA IN MEMORY (mbs): " round((r(width)+4)*r(N)/1024^3,.00001)*1000 ;
  5.         end ;

. ***************************************************************************;
. * SIMULATED MEASURES ;
. ***************************************************************************;
. program define simulator ;
  1.         args year suffix sample ;
  2.         di "BEGIN SIMULATOR - `year' `suffix' `sample'" ;
  3.         if "`sample'"=="uniform"{;
  4.                 * CREATE A UNIFORM DISTRIBUTION OF EARNINGS ;
.                 use cpi ;
  5.                 keep if year >= 1984 & year <= 2013 ;
  6.                 expand 100 ;
  7.                 sort year ;
  8.                 by year : gen pwages = 500 * (_n) ;
  9.                 by year : gen earn = 5 * (_n-1) ;
 10.                 expand 52 ;
 11.                 sort year pwages ;
 12.                 by year pwages : gen state = _n-1 ;
 13.                 expand 4 ;
 14.                 sort year pwages state ;
 15.                 by year pwages state : gen byte depx = _n-1 ;
 16.                 gen byte famsize = depx+1 ;
 17.                 gen byte depchild = depx ;
 18.                 gen byte children = depx ;
 19.                 gen byte mstat = 1 ;
 20.                 replace pwages = pwages * (cpi/232.957) ;
 21.                 replace earn = earn * (cpi/232.957) ;
 22.                 gen byte unearn = 0 ;
 23.                 gen byte wtsupp=1 ;
 24.                 };
 25.         else {;
 26.                 * SIMULATED INSTRUMENT USING THE CPS ;
.                 use cpi ;
 27.                 summ cpi if year == `year' ;
 28.                 local cpiSIV = r(mean) ;
 29.                 keep if year >= 1984 & year <= 2013 ;
 30.                 save cpiSpreadCPS, replace ;
 31.                 clear ;
 32.                 use if year == `year' using cpsBeforeTaxsim ;
 33.                 keep if `sample' ;
 34.                 count ;
 35.                 gen byte children = qualChild ;
 36.                 replace children = 3 if qualChild > 3 ;
 37.                 replace famsize = min(qualChild+1,4);
 38.                 gen earn = (pwages+swages)/12 ;
 39.                 gen unearn = max(otherprop+dividends+pensions+ui,0)/12 ;
 40.                 keep wtsupp children state agex depx depchild mstat pwages swages gssi pensions ui otherprop transfers famsize earn unearn;
 41.                 rename state state_orig ;
 42.                 gen id = _n ;
 43.                 cross using cpiSpreadCPS ;
 44.                 sizer ;
 45.                 capture rm cpiSpreadCPS.dta ;
 46.                 foreach var of varlist pwages swages gssi pensions ui otherprop transfers earn unearn {;
 47.                         qui replace `var' = `var' * cpi/`cpiSIV' ;
 48.                         };
 49.                 qui expand 52 ;
 50.                 sort id year ;
 51.                 by id year : gen byte state = _n - 1 ;
 52.                 *drop id ;
.                 };
 53.         sizer ;
 54.         capture rm msg.txt;
 55.         capture rm taxsim_out.dta;
 56.         ankurs_taxsim, full replace;
 57.         capture rm msg.txt;
 58.         capture rm taxsim_out.dta;
 59.         keep year state children v25 v39 v19 v22 v23 siitax v27 v40 cpi wtsupp famsize earn unearn;
 60.         rename v25 fedEICSIV;
 61.         rename v39 stEICSIV ;
 62.         rename v19 fedRegTaxSIV ;
 63.         egen ctcSIV = rowtotal(v22 v23) ;
 64.         rename v27 amtSIV ;
 65.         gen stCredSIV = v40-stEICSIV ;
 66.         gen stRegTaxSIV = siitax+v40 ;
 67.         sort state year famsize ;
 68.         merge m:1 state year famsize using afdcparameterstemp2012 ;
 69.         drop if _merge == 2;
 70.         tab famsize _merge ;
 71.         tab year _merge ;
 72.         drop _merge ;
 73.         gen afdcSIV = afdccb*max(afdcmax-max(afdctax*(earn-afdcdis),0)-unearn,0) ;
 74.         replace afdcSIV = 0 if children == 0 ;
 75.         replace afdcSIV = afdcSIV*12 ;
 76.         keep year state children fedEICSIV fedRegTaxSIV ctcSIV amtSIV
>                 stEICSIV stRegTaxSIV stCredSIV cpi wtsupp afdcSIV ;
 77.         sort year state children ;
 78.         collapse (mean) fedEICSIV fedRegTaxSIV ctcSIV amtSIV stEICSIV stRegTaxSIV stCredSIV afdcSIV cpi [aw=wtsupp], 
>                 by(year state children) ;
 79.         foreach var of varlist fedEICSIV fedRegTaxSIV
>                         ctcSIV amtSIV stEICSIV stRegTaxSIV stCredSIV afdcSIV {;
 80.                 qui replace `var' = `var' * (232.957/cpi);
 81.                 rename `var' `var'_`suffix' ;
 82.                 };
 83.         drop cpi ;
 84.         sort year state children ;
 85.         save simulatedmeasures`suffix', replace ;
 86.         clear ;
 87.         end ;

. use afdcparameters ;

. expand 2 if year == 2011 ;
(468 observations created)

. sort state famsize year  ;

. by state famsize year: replace year = 2012 if year == 2011 & _n==2;
(468 real changes made)

. expand 2 if year == 2011 ;
(468 observations created)

. sort state famsize year  ;

. by state famsize year: replace year = 2013 if year == 2011 & _n==2;
(468 real changes made)

. duplicates report state famsize year ;

Duplicates in terms of state famsize year

--------------------------------------
   copies | observations       surplus
----------+---------------------------
        1 |        15444             0
--------------------------------------

. sort state year famsize ;

. save afdcparameterstemp2012, replace ;
file afdcparameterstemp2012.dta saved

. clear ;

. simulator "" "uni" "uniform" ;
BEGIN SIMULATOR -  uni uniform
(71 observations deleted)
(2,970 observations created)
(153,000 observations created)
(468,000 observations created)
(603,200 real changes made)
(597,168 real changes made)
OBSERVATIONS: 624000
DATA IN MEMORY (gbs): .017
DATA IN MEMORY (mbs): 16.85
begin taxsim9.ado on 13 Apr 2018 (version 9.0)
TAXSIM results will be merged to original file
TAXSIM results will be saved in taxsim_out.dta
Full Intermediate Calculations Requested
Marginal rate with respect to primary earner
Variable agex is not in the dataset.  Generating agex = 0 
Variable swages is not in the dataset.  Generating swages = 0 
Variable dividends is not in the dataset.  Generating dividends = 0 
Variable otherprop is not in the dataset.  Generating otherprop = 0 
Variable pensions is not in the dataset.  Generating pensions = 0 
Variable gssi is not in the dataset.  Generating gssi = 0 
Variable transfers is not in the dataset.  Generating transfers = 0 
Variable rentpaid is not in the dataset.  Generating rentpaid = 0 
Variable proptax is not in the dataset.  Generating proptax = 0 
Variable otheritem is not in the dataset.  Generating otheritem = 0 
Variable childcare is not in the dataset.  Generating childcare = 0 
Variable ui is not in the dataset.  Generating ui = 0 
Variable mortgage is not in the dataset.  Generating mortgage = 0 
Variable stcg is not in the dataset.  Generating stcg = 0 
Variable ltcg is not in the dataset.  Generating ltcg = 0 
624000 records out of 624000 are left for taxsim to process
 
TAXSIM results are being merged with workspace by taxsimid
(note: variable year was int, now float to accommodate using data's values)
 

    Result                           # of obs.
    -----------------------------------------
    not matched                       166,764
        from master                   156,000  (_merge==1)
        from using                     10,764  (_merge==2)

    matched                           468,000  (_merge==3)
    -----------------------------------------
(10,764 observations deleted)

           |        _merge
   famsize | master on  matched ( |     Total
-----------+----------------------+----------
         1 |   156,000          0 |   156,000 
         2 |         0    156,000 |   156,000 
         3 |         0    156,000 |   156,000 
         4 |         0    156,000 |   156,000 
-----------+----------------------+----------
     Total |   156,000    468,000 |   624,000 


           |        _merge
      year | master on  matched ( |     Total
-----------+----------------------+----------
      1984 |     5,200     15,600 |    20,800 
      1985 |     5,200     15,600 |    20,800 
      1986 |     5,200     15,600 |    20,800 
      1987 |     5,200     15,600 |    20,800 
      1988 |     5,200     15,600 |    20,800 
      1989 |     5,200     15,600 |    20,800 
      1990 |     5,200     15,600 |    20,800 
      1991 |     5,200     15,600 |    20,800 
      1992 |     5,200     15,600 |    20,800 
      1993 |     5,200     15,600 |    20,800 
      1994 |     5,200     15,600 |    20,800 
      1995 |     5,200     15,600 |    20,800 
      1996 |     5,200     15,600 |    20,800 
      1997 |     5,200     15,600 |    20,800 
      1998 |     5,200     15,600 |    20,800 
      1999 |     5,200     15,600 |    20,800 
      2000 |     5,200     15,600 |    20,800 
      2001 |     5,200     15,600 |    20,800 
      2002 |     5,200     15,600 |    20,800 
      2003 |     5,200     15,600 |    20,800 
      2004 |     5,200     15,600 |    20,800 
      2005 |     5,200     15,600 |    20,800 
      2006 |     5,200     15,600 |    20,800 
      2007 |     5,200     15,600 |    20,800 
      2008 |     5,200     15,600 |    20,800 
      2009 |     5,200     15,600 |    20,800 
      2010 |     5,200     15,600 |    20,800 
      2011 |     5,200     15,600 |    20,800 
      2012 |     5,200     15,600 |    20,800 
      2013 |     5,200     15,600 |    20,800 
-----------+----------------------+----------
     Total |   156,000    468,000 |   624,000 

(156,000 missing values generated)
(156,000 real changes made)
(462,648 real changes made)
(note: file simulatedmeasuresuni.dta not found)
file simulatedmeasuresuni.dta saved

. simulator "1982" "82cps" "statefip!=2&statefip!=15&incdisab==0&incss==0&incssi==0&age>=24&age<=48" ;
BEGIN SIMULATOR - 1982 82cps statefip!=2&statefip!=15&incdisab==0&incss==0&incssi==0&age>=24&age<=48

    Variable |        Obs        Mean    Std. Dev.       Min        Max
-------------+---------------------------------------------------------
         cpi |          1        96.5           .       96.5       96.5
(71 observations deleted)
(note: file cpiSpreadCPS.dta not found)
file cpiSpreadCPS.dta saved
(610 observations deleted)
  7,630
(272 real changes made)
(2,680 real changes made)
OBSERVATIONS: 228900
DATA IN MEMORY (gbs): .012
DATA IN MEMORY (mbs): 12.36
OBSERVATIONS: 11902800
DATA IN MEMORY (gbs): .654
DATA IN MEMORY (mbs): 654.04
begin taxsim9.ado on 13 Apr 2018 (version 9.0)
TAXSIM results will be merged to original file
TAXSIM results will be saved in taxsim_out.dta
Full Intermediate Calculations Requested
Marginal rate with respect to primary earner
Variable dividends is not in the dataset.  Generating dividends = 0 
Variable rentpaid is not in the dataset.  Generating rentpaid = 0 
Variable proptax is not in the dataset.  Generating proptax = 0 
Variable otheritem is not in the dataset.  Generating otheritem = 0 
Variable childcare is not in the dataset.  Generating childcare = 0 
Variable mortgage is not in the dataset.  Generating mortgage = 0 
Variable stcg is not in the dataset.  Generating stcg = 0 
Variable ltcg is not in the dataset.  Generating ltcg = 0 
11902800 records out of 11902800 are left for taxsim to process
 
TAXSIM results are being merged with workspace by taxsimid
(note: variable year was int, now float to accommodate using data's values)
(note: variable state was byte, now float to accommodate using data's values)
 
(3,519,767 missing values generated)
(3,519,767 missing values generated)

    Result                           # of obs.
    -----------------------------------------
    not matched                     6,969,925
        from master                 6,959,161  (_merge==1)
        from using                     10,764  (_merge==2)

    matched                         4,943,640  (_merge==3)
    -----------------------------------------
(10,764 observations deleted)

           |        _merge
   famsize | master on  matched ( |     Total
-----------+----------------------+----------
         1 | 6,959,160          0 | 6,959,160 
         2 |         0  2,071,680 | 2,071,680 
         3 |         0  1,681,680 | 1,681,680 
         4 |         0  1,190,280 | 1,190,280 
-----------+----------------------+----------
     Total | 6,959,160  4,943,640 |11,902,800 


           |        _merge
      year | master on  matched ( |     Total
-----------+----------------------+----------
         0 |         1          0 |         1 
      1984 |   231,972    164,788 |   396,760 
      1985 |   231,972    164,788 |   396,760 
      1986 |   231,972    164,788 |   396,760 
      1987 |   231,972    164,788 |   396,760 
      1988 |   231,972    164,788 |   396,760 
      1989 |   231,972    164,788 |   396,760 
      1990 |   231,972    164,788 |   396,760 
      1991 |   231,972    164,788 |   396,760 
      1992 |   231,972    164,788 |   396,760 
      1993 |   231,972    164,788 |   396,760 
      1994 |   231,972    164,788 |   396,760 
      1995 |   231,972    164,788 |   396,760 
      1996 |   231,972    164,788 |   396,760 
      1997 |   231,972    164,788 |   396,760 
      1998 |   231,972    164,788 |   396,760 
      1999 |   231,972    164,788 |   396,760 
      2000 |   231,972    164,788 |   396,760 
      2001 |   231,972    164,788 |   396,760 
      2002 |   231,972    164,788 |   396,760 
      2003 |   231,972    164,788 |   396,760 
      2004 |   231,972    164,788 |   396,760 
      2005 |   231,972    164,788 |   396,760 
      2006 |   231,972    164,788 |   396,760 
      2007 |   231,972    164,788 |   396,760 
      2008 |   231,972    164,788 |   396,760 
      2009 |   231,972    164,788 |   396,760 
      2010 |   231,972    164,788 |   396,760 
      2011 |   231,972    164,788 |   396,760 
      2012 |   231,972    164,788 |   396,760 
      2013 |   231,972    164,788 |   396,760 
-----------+----------------------+----------
     Total | 6,959,161  4,943,640 |11,902,801 

(6,959,161 missing values generated)
(6,959,160 real changes made)
(1,991,115 real changes made)
(note: file simulatedmeasures82cps.dta not found)
file simulatedmeasures82cps.dta saved

. simulator "1992" "92cps" "statefip!=2&statefip!=15&incdisab==0&incss==0&incssi==0&age>=24&age<=48" ;
BEGIN SIMULATOR - 1992 92cps statefip!=2&statefip!=15&incdisab==0&incss==0&incssi==0&age>=24&age<=48

    Variable |        Obs        Mean    Std. Dev.       Min        Max
-------------+---------------------------------------------------------
         cpi |          1       140.3           .      140.3      140.3
(71 observations deleted)
(note: file cpiSpreadCPS.dta not found)
file cpiSpreadCPS.dta saved
(740 observations deleted)
  9,100
(266 real changes made)
(2,857 real changes made)
OBSERVATIONS: 273000
DATA IN MEMORY (gbs): .015
DATA IN MEMORY (mbs): 14.75
OBSERVATIONS: 14196000
DATA IN MEMORY (gbs): .78
DATA IN MEMORY (mbs): 780.04
begin taxsim9.ado on 13 Apr 2018 (version 9.0)
TAXSIM results will be merged to original file
TAXSIM results will be saved in taxsim_out.dta
Full Intermediate Calculations Requested
Marginal rate with respect to primary earner
Variable dividends is not in the dataset.  Generating dividends = 0 
Variable rentpaid is not in the dataset.  Generating rentpaid = 0 
Variable proptax is not in the dataset.  Generating proptax = 0 
Variable otheritem is not in the dataset.  Generating otheritem = 0 
Variable childcare is not in the dataset.  Generating childcare = 0 
Variable mortgage is not in the dataset.  Generating mortgage = 0 
Variable stcg is not in the dataset.  Generating stcg = 0 
Variable ltcg is not in the dataset.  Generating ltcg = 0 
14196000 records out of 14196000 are left for taxsim to process
 
TAXSIM results are being merged with workspace by taxsimid
(note: variable year was int, now float to accommodate using data's values)
(note: variable state was byte, now float to accommodate using data's values)
 
(5,860,836 missing values generated)
(5,860,836 missing values generated)

    Result                           # of obs.
    -----------------------------------------
    not matched                     8,274,085
        from master                 8,263,321  (_merge==1)
        from using                     10,764  (_merge==2)

    matched                         5,932,680  (_merge==3)
    -----------------------------------------
(10,764 observations deleted)

           |        _merge
   famsize | master on  matched ( |     Total
-----------+----------------------+----------
         1 | 8,263,320          0 | 8,263,320 
         2 |         0  2,625,480 | 2,625,480 
         3 |         0  2,065,440 | 2,065,440 
         4 |         0  1,241,760 | 1,241,760 
-----------+----------------------+----------
     Total | 8,263,320  5,932,680 |14,196,000 


           |        _merge
      year | master on  matched ( |     Total
-----------+----------------------+----------
        20 |         1          0 |         1 
      1984 |   275,444    197,756 |   473,200 
      1985 |   275,444    197,756 |   473,200 
      1986 |   275,444    197,756 |   473,200 
      1987 |   275,444    197,756 |   473,200 
      1988 |   275,444    197,756 |   473,200 
      1989 |   275,444    197,756 |   473,200 
      1990 |   275,444    197,756 |   473,200 
      1991 |   275,444    197,756 |   473,200 
      1992 |   275,444    197,756 |   473,200 
      1993 |   275,444    197,756 |   473,200 
      1994 |   275,444    197,756 |   473,200 
      1995 |   275,444    197,756 |   473,200 
      1996 |   275,444    197,756 |   473,200 
      1997 |   275,444    197,756 |   473,200 
      1998 |   275,444    197,756 |   473,200 
      1999 |   275,444    197,756 |   473,200 
      2000 |   275,444    197,756 |   473,200 
      2001 |   275,444    197,756 |   473,200 
      2002 |   275,444    197,756 |   473,200 
      2003 |   275,444    197,756 |   473,200 
      2004 |   275,444    197,756 |   473,200 
      2005 |   275,444    197,756 |   473,200 
      2006 |   275,444    197,756 |   473,200 
      2007 |   275,444    197,756 |   473,200 
      2008 |   275,444    197,756 |   473,200 
      2009 |   275,444    197,756 |   473,200 
      2010 |   275,444    197,756 |   473,200 
      2011 |   275,444    197,756 |   473,200 
      2012 |   275,444    197,756 |   473,200 
      2013 |   275,444    197,756 |   473,200 
-----------+----------------------+----------
     Total | 8,263,321  5,932,680 |14,196,001 

(8,263,321 missing values generated)
(8,263,320 real changes made)
(2,395,133 real changes made)
(note: file simulatedmeasures92cps.dta not found)
file simulatedmeasures92cps.dta saved

. use simulatedmeasuresuni ;

. foreach suffix in 82cps 92cps {;
  2.         sort year state children ;
  3.         merge 1:1 year state children using simulatedmeasures`suffix' ;
  4.         drop _merge ;
  5.         rm simulatedmeasures`suffix'.dta ;
  6.         };

    Result                           # of obs.
    -----------------------------------------
    not matched                             0
    matched                             6,240  (_merge==3)
    -----------------------------------------

    Result                           # of obs.
    -----------------------------------------
    not matched                             0
    matched                             6,240  (_merge==3)
    -----------------------------------------

. rm simulatedmeasuresuni.dta ;

. rm afdcparameterstemp2012.dta ;

. save simulatedmeasures, replace ;
file simulatedmeasures.dta saved

. clear ;

. disp "`beginTime'" ;
DateTime: 13 Apr 2018 11:52:42

. disp "DateTime: $S_DATE $S_TIME";
DateTime: 13 Apr 2018 13:20:57

. */
> *;
. disp "`beginTime'" ;
DateTime: 13 Apr 2018 11:52:42

. disp "DateTime: $S_DATE $S_TIME";
DateTime: 13 Apr 2018 13:20:57

. log close ;
      name:  <unnamed>
       log:  2_SingleWomen_simCredit.log
  log type:  text
 closed on:  13 Apr 2018, 13:20:57
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
